<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>

        <ui:composition template="./template.xhtml">

            <ui:define name="title">
                Truy vấn thông tin giao dịch thẻ cào
            </ui:define>

            <ui:define name="content">
                <h:form id="inputForm">
                    <p:panel>
                        <h:panelGrid columns="2">
                            Ngày bắt đầu* 
                            <p:calendar value="#{transactionQueryBean.queryObject.startTime}" pattern="dd/MM/yyyy HH:mm:ss" timeZone="Asia/Saigon" navigator="true"
                                        required="true" requiredMessage="Bạn chưa chọn ngày bắt đầu"> 
                            </p:calendar>
                            Ngày kết thúc* 
                            <p:calendar value="#{transactionQueryBean.queryObject.endTime}" pattern="dd/MM/yyyy HH:mm:ss" timeZone="Asia/Saigon" navigator="true"
                                        required="true" requiredMessage="Bạn chưa chọn ngày kết thúc"/>

                            Đối tác
                            <p:selectOneMenu value="#{transactionQueryBean.queryObject.accId}">
                                <f:selectItem itemLabel="Tất cả" itemValue="ALL"/>
                                <f:selectItems value="#{partnerBean.partnerIdMap}"/>
                            </p:selectOneMenu>

                            Mã giao dịch
                            <p:inputText value="#{transactionQueryBean.queryObject.transId}" />
                            Seri thẻ
                            <p:inputText value="#{transactionQueryBean.queryObject.cardSerial}" />
                            PIN thẻ
                            <p:inputText value="#{transactionQueryBean.queryObject.cardPin}" />
                            Loại giao dịch
                            <p:selectOneMenu value="#{transactionQueryBean.queryObject.transType}">
                                <f:selectItem itemLabel="topup" itemValue="topup"/>
                                <f:selectItem itemLabel="transfer" itemValue="transfer"/>
                                <f:selectItem itemLabel="refund" itemValue="refund"/>
                                <f:selectItem itemLabel="unknown" itemValue="unknown"/>
                            </p:selectOneMenu>
                            Số tiền từ <p:inputText value="#{transactionQueryBean.queryObject.amountMin}"/>
                            đến <p:inputText value="#{transactionQueryBean.queryObject.amountMax}"/>
                        </h:panelGrid>

                        <h:panelGrid columns="5">
                            <p:commandButton ajax="false" value="Truy vấn" action="#{transactionQueryBean.query()}"/>
                        </h:panelGrid>
                    </p:panel>
                </h:form>

                <br/>

                <h:form id="tableForm">
                    <p:dataTable value="#{transactionQueryBean.list}" var="item" paginator="#{transactionQueryBean.list.size() >20}" rows="20" >
                        <p:column headerText="Mã giao dịch" sortBy="#{item}">
                            #{item.transactionPK.transId}
                        </p:column>
                        <p:column headerText="Đối tác" sortBy="#{item.transactionPK.accId}">
                            #{item.transactionPK.accId}
                        </p:column>
                        <p:column headerText="IP" sortBy="#{item.ip}">
                            #{item.ip}
                        </p:column>
                        <p:column headerText="Loại giao dịch" sortBy="#{item.transType}">
                            #{item.transType}
                        </p:column>
                        <p:column headerText="Số tiền" sortBy="#{item.amount}">
                            <p:cellEditor>  
                                <f:facet name="output"><h:outputText value="#{item.amount}" /></f:facet>  
                                <f:facet name="input"><p:inputText id="modelInput" value="#{item.amount}" style="width:96%"/></f:facet>  
                            </p:cellEditor>
                        </p:column>
                        <p:column headerText="Seri" sortBy="#{item.cardSerial}">
                            #{item.cardSerial}
                        </p:column>
                        <p:column headerText="PIN" sortBy="#{item.cardPin}">
                            #{item.cardPin}
                        </p:column>
                        <p:column headerText="Thời gian">
                            <h:outputText value="#{item.lastUpdatedTime}">
                                <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" timeZone="Asia/Saigon"/>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Kết quả" sortBy="#{item.transErr}">
                            #{item.transErr} - #{item.transErrDetail}
                        </p:column>
                        <p:column headerText="Xác nhận thành công">
                            <p:commandButton ajax="false" value="Xác nhận" action="#{transactionQueryBean.confirmSuccessTransaction(item)}"
                                             rendered="#{item.transErr != '01'}"/>
                        </p:column>
                    </p:dataTable>
                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>
